﻿namespace Blaze.Editor
{
    using System.Collections.Generic;
    using UnityEditor;
    using UnityEngine;

    /// <summary>
    /// 提供编辑器内置样式的便携访问。
    /// </summary>
    public static class EditorGUIStyle
    {
        public static GUIStyle ExposablePopupMenu
        {
            get { return getStyle("exposablePopupMenu"); }
        }

        public static GUIStyle InBigTitle
        {
            get { return getStyle("In BigTitle"); }
        }

        public static GUIStyle PreButton
        {
            get { return getStyle("preButton"); }
        }

        public static GUIStyle PreLabel
        {
            get { return getStyle("preLabel"); }
        }

        public static GUIStyle PreSlider
        {
            get { return getStyle("preSlider"); }
        }

        public static GUIStyle PreSliderThumb
        {
            get { return getStyle("preSliderThumb"); }
        }

        private static GUIStyle getStyle(string name)
        {
            GUIStyle ret;
            if (mCache.TryGetValue(name, out ret))
                return ret;

            ret = GUI.skin.FindStyle(name) ?? EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle(name);
            if (ret == null)
            {
                Debug.LogError("Missing built-in guistyle " + name);
                ret = new GUIStyle(name);
            }

            mCache.Add(name, ret);
            return ret;
        }

        private static readonly Dictionary<string, GUIStyle> mCache = new Dictionary<string, GUIStyle>();
    }
}